package com.bf.xpdd.util;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.bf.xpdd.domain.ActivityRecordBean;
import com.bf.xpdd.domain.AnalysisData;

public class AnalysisUtility
{

	/**
	 * 从活动成交记录中提取统计数据
	 * 
	 * @param list
	 * @param data
	 * @param map 存放总的成交数和成交金额
	 */
	public static void getAnalysisDataFromRecords(List<ActivityRecordBean> list, AnalysisData analysis, Map<String, Number> map)
	{
		int[] data = new int[DateUtility.getMaxDayOfMonth()];
		for (ActivityRecordBean record : list)
		{
			Date d = record.getRecordTime();
			int num = record.getBuyNum();
			int index = DateUtility.getDayOfMonth(d);
			data[index - 1] += num;
			//totalNum
			int totalNum = map.get("totalNum").intValue();
			totalNum += num;
			map.put("totalNum", totalNum);
			//totalPrice
			double totalPrice = map.get("totalPrice").doubleValue();
			totalPrice += num * record.getPrice();
			map.put("totalPrice", totalPrice);
		}
		analysis.setData(data);
	}
	
}
